<?php

class BaseAction extends Action {

    public $user_info = '',$erp='erp';

    function __construct() {
        $user_info = $this->getUserInfo();
		//var_dump($user_info);
        if (empty($user_info)) {
            //header("Location:/index.php?s=User");
			header("Location:".U ( 'User/index'));
            die();
        }
        $this->user_info = $user_info;
        $classname = $this->leftStyle();
		$this->assign('username',$this->user_info['username']);
        $this->assign('classname', $classname);
    }

    //获取用户信息
    private function getUserInfo() {
        $user_info = array();
        $userid = $_COOKIE['UserID'];
        if (!empty($userid)) {
            $user_model = M('mer_user');
            $data = $user_model->where("id=" . $userid)->find();
            $user_info['userid'] = $data['id'];
            $user_info['username'] = $data['username'];
        }
        return $user_info;
    }

    //左边样式
    private function leftStyle() {
        $classname = $_REQUEST['classname'];
        if (empty($classname)) {
            $classname = "home";
        }
        return $classname;
    }

    //操作日志记录
    protected function saveLogData($data) {
        $log_model = M('mer_log');
        $log_data['type'] = $data['type'];
        $log_data['content'] = $data['content'];
        $log_data['mer_userid'] = $this->user_info['userid'];
        $log_data['addtime'] = date('Y-m-d H:i:s');
        $log_model->data($log_data)->add();
    }

}

?>